﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Security;

namespace hsgsSHXX.BLL
{
    /// <summary>
    /// 用户管理逻辑类
    /// </summary>
    public class User
    {
        public User()
        {
        }
        /// <summary>
        /// 根据组织编号获取用户列表
        /// <creator>wangl</creator>
        /// <date>2012-06-11</date>
        /// </summary>
        /// <param name="orgNo"></param>
        /// <returns></returns>
        public List<Model.PrvUser> GetPrvUserListByOrgNo(string orgNo)
        {
            DAL.PrvUser prvUserDAL = new DAL.PrvUser();
            return prvUserDAL.GetPrvUserListByOrgNo(orgNo);
        }
        /// <summary>
        /// 分页获取用户列表
        /// <creator>wangl</creator>
        /// <date>2012-06-11</date>
        /// </summary>
        public List<Model.PrvUser> GetPrvUserListByPage(int pageSize, int pageIndex, string strWhere, string fOrderFiled, int orderType, out int total)
        {
            DAL.PrvUser prvUserDAL = new DAL.PrvUser();
            return prvUserDAL.GetListByPage(pageSize, pageIndex, strWhere, fOrderFiled, orderType, out total);
        }
       
        /// <summary>
        /// 原密码是否正确
        /// <creator>wuxp</creator>
        /// <date>2012-06-27</date>
        /// </summary>
        public bool IsPasswordMatch(string fLoginID, string FPassword)
        {
            DAL.PrvUser prvUserDAL = new DAL.PrvUser();
            string strNewPassword = GetMd5Password(fLoginID, FPassword);
            return prvUserDAL.IsPasswordMatch(fLoginID, strNewPassword);
        }
        /// <summary>
        /// 是否存在相同的身份证号
        /// </summary>
        /// <param name="loginID"></param>
        /// <returns></returns>
        public bool ExistsLoginID(string loginID)
        {
            DAL.PrvUser prvUserDAL = new DAL.PrvUser();
            return prvUserDAL.Exists(loginID);
        }
         /// <summary>
        /// 添加用户，同时添加用户组
        /// <creator>wangl</creator>
        /// <date>2012-06-14</date>
        /// </summary>
        /// <param name="model"></param>
        /// <param name="groupList"></param>
        public void AddUser(Model.PrvUser model, List<string> groupList)
        {
            DAL.PrvUser prvUserDAL = new DAL.PrvUser();
            prvUserDAL.AddUser(model, groupList);
        }
        /// <summary>
        /// 获取用户对象
        /// <creator>wangl</creator>
        /// <date>2012-06-14</date>
        /// </summary>
        /// <param name="loginID"></param>
        /// <returns></returns>
        public Model.PrvUser GetUserModel(string loginID)
        {
            DAL.PrvUser prvUserDAL = new DAL.PrvUser();
            return prvUserDAL.GetModel(loginID);
        }


        /// <summary>
        /// 更新用户，同时修改用户组
        /// <creator>wangl</creator>
        /// <date>2012-06-14</date>
        /// </summary>
        /// <param name="model"></param>
        /// <param name="groupList"></param>
        public void UpdateUser(Model.PrvUser model, List<string> groupList)
        {
            DAL.PrvUser prvUserDAL = new DAL.PrvUser();
            prvUserDAL.UpdateUser(model, groupList);
        }

        /// <summary>
        /// 删除用户
        /// <creator>wangl</creator>
        /// <date>2012-06-15</date>
        /// </summary>
        /// <param name="loginID"></param>
        public void DeleteUser(string loginID)
        {
            DAL.PrvUser prvUserDAL = new DAL.PrvUser();
            prvUserDAL.DeleteUser(loginID);
        }
        /// <summary>
        /// 批量删除用户
        /// <creator>wangl</creator>
        /// <date>2012-06-15</date>
        /// </summary>
        /// <param name="userLoginList"></param>
        public void DeleteUserList(List<string> userLoginList)
        {
            DAL.PrvUser prvUserDAL = new DAL.PrvUser();
            prvUserDAL.DeleteUserList(userLoginList);
        }
        /// <summary>
        /// 更新用户密码
        /// </summary>
        /// <create>wuxp</create>
        /// <date>2012-06-27</date>
        /// <param name="FLOGID">用户登录ID</param>
        /// <param name="FPASSWORD">新密码</param>
        public void UpdatePassword(string fLogID, string fPassword)
        {
            DAL.PrvUser prvUserDAL = new DAL.PrvUser();
            string strNewPassword = GetMd5Password(fLogID, fPassword);
            prvUserDAL.UpdatePassword(fLogID, strNewPassword);
        }
        /// <summary>
        /// 根据用户登录名跟密码获取MD5密码，算法：用户名加密码后再取MD5值
        /// </summary>
        /// <creator>wuxp</creator>
        /// <date>2012-06-27</date>
        public string GetMd5Password(string loginId, string passWord)
        {
            string newPassword = FormsAuthentication.HashPasswordForStoringInConfigFile(loginId + passWord, "MD5");
            return newPassword;
        }
        /// <summary>
        /// 批量重置密码
        /// <creator>wangl</creator>
        /// <date>2012-06-15</date>
        /// </summary>
        /// <param name="userLoginList"></param>
        public void ResetPwdUserList(List<string> userLoginList)
        {
            DAL.PrvUser prvUserDAL = new DAL.PrvUser();
            prvUserDAL.ResetPwdUserList(userLoginList);
        }

        /// <summary>
        /// 获取登录ID的姓名
        /// <creator>wangl</creator>
        /// <date>2012-07-02</date>
        /// </summary>
        /// <param name="loginID"></param>
        /// <returns></returns>
        public string GetLoginName(string loginID)
        {
            DAL.PrvUser prvUserDAL = new DAL.PrvUser();
            return prvUserDAL.GetLoginName(loginID);
        }


        /// <summary>
        /// 获取所有用户列表
        /// <creator>wangl</creator>
        /// <date>2012-10-16</date>
        /// </summary>
        /// <returns></returns>
        public List<Model.PrvUser> GetPrvUserListAll()
        {
            DAL.PrvUser prvUserDAL = new DAL.PrvUser();
            return prvUserDAL.GetPrvUserListAll();
        }
        public List<Model.PrvUser> GetFondListByPage(int pageSize, int pageIndex, string strWhere, string fOrderFiled, out int total)
        {
            DAL.PrvUser FondDAL = new DAL.PrvUser();
            return FondDAL.GetFondListByPage(pageSize, pageIndex, strWhere, fOrderFiled, out total);
        }
    }
}
